<?PHP
	header ( "Content-type:text/html;charset=utf-8" );
	require_once('../php/db/properties.inc.php');
	session_start();
	@$userInfo = $_SESSION["userInfo"];
	$userObj = "";
    $sessionUserId="";
	if(!empty($userInfo)){
		$userObj = json_decode($userInfo);
		$sessionUserId=$userObj-> id;
	}	
	
?>
<!DOCTYPE html>
<html >
 <head>
  <title>淡炒番茄 </title>
  <meta charset="UTF-8"/>
  <meta name="description" content="不知道为什么就是想写个网站玩儿，但技术不行将就用吧!"/>
  <meta name="viewport"  content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"/>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="keywords" content=""/>
  <meta name="robots" content="index,follow" />
  <meta name="full-screen" content="yes">
  <meta name="x5-fullscreen" content="true">
  <link href="../css/common.css" rel="stylesheet"/>
  <link href="../css/content.css" rel="stylesheet"/>
  <script type="text/javascript" src="../js/jquery-3.1.1.min.js"></script>
  <script type="text/javascript" src="../js/smallarAlert.js"></script>
  <script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
  <script type="text/javascript" src="../ueditor/ueditor.all.js"></script>
  <script type="text/javascript" src="../ueditor/ueditor.parse.js"></script>
  <script type="text/javascript">
     var ua = navigator.userAgent;
     window.onload = function(){
         if(ua.match(/(iPhone|iPod|Android|ios)/i)){
             $(".dfb").css("width","100%");
             $(".contnrhe").css("width","100%");
             $(".contnrr").css("width","100%");
         }
     };
  </script>
</head>
<body class="dfb">
	<div class="bodco bodyd" >
		<div class="contbt">
			<ul>
				<li><a href="list.php?type=2" class="fonts1 font3 remFlo clicks1">小技术</a></li>
				<li><p  class="fonts font1">|</p></li>
				<li><a href="list.php?type=1" class="fonts1 font3 remFlo clicks1">小信息</a></li>
			</ul>
		</div>
		<div class="contnr">
			<div class="contnrhe">
				<?php

					$id = $_GET["id"];
					$conn = new mysqli($url, $user, $pwd, $dbname, $port);
					$headName = "";
					$headImg = "";
					$contTitle = "";
					$blogId="";
					$provinces = "";
					$city = "";
					$userId = "";
					$content ="";
					$conn -> set_charset("utf8");
					$sql = "SELECT b.addTime,b.id,b.title,b.addTime,b.userId,u.userName,c.city,p.province as provinces ,t.content,u.head FROM bolggerTitle b,bolggerContent t,userInfo u left JOIN hatProvince p ON u.provinces=p.provinceID LEFT JOIN hatCity c ON u.city=c.cityID   WHERE  b.id=t.titleId AND b.userId=u.id AND b.id=".$id;
					
					if(!$conn->connect_error){
						$results = $conn->query($sql);
						while ($row = $results->fetch_object()) {
					     	$headName = $row->userName; 
					     	$headImg = $row->head; 
					     	$provinces = $row->provinces;
							$city = $row->city;
							$userId = $row->userId;
							$content = $row->content; 
							$contTitle = $row->title; 
							$addTime = $row->addTime; 
							$blogId = $row->id; 
					    }
					    $results->close();
					}
					$conn -> close();
				?>
				<?php
					$htmlHead="<div class='contnrheim'>";
					if($headImg){
						$htmlHead .= "<img class='contnrheimm'  src='".$headImg."'>";
					}else{
						$htmlHead .= "<img class='contnrheimm'  src='../img/he.png'>";
					}
					
					$htmlHead .= "</div>";
					$htmlHead .= "<div class='fonts font3 contnrhecon'>".$headName."</div>";
					$htmlHead .= "<div class='fonts font2 contnrhecon contnrhetext'>地址：";
					$htmlHead .= ($provinces) ? ($provinces."-". $city) : "未知" ;
					$htmlHead .= "</div>";
					if($sessionUserId!=""&&$sessionUserId==$userId){
						$htmlHead .= "<div class='contnrhecon contnrhetext'>";
						$htmlHead .= "<a href='editUserInfo.php' class='fonts font2 clicks1 remFlo' >修改信息</a>";
						$htmlHead .= "</div>";
					}
					
					echo $htmlHead;
				?>
			</div>
			<div class="contnrr">
				<?PHP 
					//文章内容
					$dateForm = date_format(date_create($addTime),'Y-m-d');
					$htmlCont = "";
					$htmlCont .= "<div class='contnrrbot fonts1 font1 contnrrbotl' >".$contTitle."</div>";
					$htmlCont .= "<div class='contnrrbot fonts font2 contnrrbotr' >".$addTime."&nbsp;发文&nbsp;";
					if(!empty($userInfo)&&($userObj->id)==$userId){
						$htmlCont .= "[<a href='editcon.php?blogId=".$blogId."' style='text-decoration: none;'>修改</a>]";
					}
					$htmlCont .= "</div>";
					$htmlCont .= "<div class='contnrrbotcon''><div id='ueditorCont' class='contnrrbotcone'>";
					$htmlCont .= $content;
					$htmlCont .= "</div>";
					echo $htmlCont;
					
					//回复
					$htmlReply = "";
					$mysqli = new mysqli($url, $user, $pwd, $dbname, $port);
					$replySql = "SELECT t.addTime,t.reply,u.userName,u.head FROM bolggerReply t,userInfo u WHERE t.userId=u.id AND t.titleId=".$id;
					if(!$mysqli->connect_error){
						$resulti = $mysqli->query($replySql);
						while ($rowi = $resulti->fetch_assoc()) {
					     	$htmlReply .= "<div class='contnrrpinl'>";
					     	if($rowi["head"]){
					     		$htmlReply .= "<div><img style='top:5px;' src='".$rowi["head"]."'></div>";
					     	}else{
					     		$htmlReply .= "<div><img style='top:5px;' src='../img/he.png'></div>";
					     	}
					     	
					     	$htmlReply .= "<div class='fonts font2 '>".$rowi["userName"]."&nbsp;[".$rowi["addTime"]."]</div>";
					     	$htmlReply .= "<hr style='width: 96%;height: 1px;background: #F9FDE4;'>";
					     	$htmlReply .= "<div class='contnrrpinlc'>";
					     	$htmlReply .= $rowi["reply"];
					     	$htmlReply .= "</div></div>";
					     }
					    $resulti->free();
					}
					$mysqli -> close();
					
					echo $htmlReply;
				?>
				</div>
				<div class="contnrrbotconme" >
					<?PHP 
					
						//用户回复
						$userReply = "";
						if($userInfo){
							$userReply .= "<div class='contnrrbotconmeed'>";
							$userReply .= "<form id='contents' accept-charset='utf-8' action='../php/action/reply.php' method='post'>";
							$userReply .= "<input style='display:none;' id='titleId' name='titleId' value='". $id ."' >";
							$userReply .= "<script id='container' name='content' type='text/javascript'></script>";
                         $userReply .= "<script type='text/javascript'>var ue = UE.getEditor('container',{toolbars: [['bold', 'italic', 'underline', 'emotion']]});</script>";
							$userReply .= "</div>";
							$userReply .= "<div class='contnrrbotconmetj' id='sumbitReplayId' onclick='sumbitReplay();'>提交";
							$userReply .= "</div>";
						}else{
							$userReply .= "<div class='contnrrbotconmetj' onclick='loginUser();'>登录";
							$userReply .= "</div>";
						}
						
						echo $userReply;
					?>
				</div>
			</div>
		</div>
	</div>
	<div class="bodco bodcohrs" ><hr class="bodyh"/></div> 
 	<div class="bodco bodyf">
 		 <p class='fonts font2'> @2016-2017 <a <a href="../index.php" class='fonts font2 ' style="text-decoration: none;" >淡炒番茄</a> （http://www.dancfq.top/)  备案号:蜀ICP备16034800号 </p>
 	</div>
 	
 	<script type="text/javascript">

 		function sumbitReplay(){
 			$("#contents").submit();
 			$("#sumbitReplayId").unbind("click");
 		}
 		
 		function loginUser(){
 			window.location.href="login.html";
 		}
 	</script>
</body>
</html>